from flask import *
from Asql import Asql #引入数据库框架
import json

run = Flask(__name__)
run.config['JSON_AS_ASCII'] = False

@run.route("/public/admin/login")
def login():
    asql = Asql()
    uid = request.args.get('uid')
    _pass = request.args.get('pass')

    if uid is None or _pass is None or uid == "" or _pass == "":
        return json.dumps({"code": 500, "msg": "参数不能留空"},ensure_ascii=False)
    else:
        
        userData = asql.SelectAll("admin",conditions=f"uid={uid}")
        #查询用户数据
        if len(userData) == 0:
            return json.dumps({"code": 500, "msg": "用户不存在"},ensure_ascii=False)      
        if asql.md5(_pass) != userData[0][1]:
            return json.dumps({"code": 500, "msg": "密码错误"},ensure_ascii=False)
        print(userData)
        return json.dumps({"code": 200, "msg": "登录成功"},ensure_ascii=False)


run.run()